package test01;

public class Phone {
    // 品牌
    private String brand;
    // 价格
    private String price;
    // 名称
    private String name;
    // 联系人列表
    private String[] contact = new String[10];

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String[] getContact() {
        return contact;
    }

    public void setContact(String[] contact) {
        this.contact = contact;
    }

    public Phone(String name) {
        System.out.println(name + "在上网");
    }

    // 添加联系人
    public void addContact(String name) {
        for (int i = 0; i < contact.length; i++) {
            if (contact[i] == null) {
                contact[i] = name;
                System.out.println("联系人" + name + "已添加");
                return;
            }
        }
        System.out.println("联系人列表已满，无法添加");
    }

    // 发短信
    public void sendMessage(String recipient, String message) {
        boolean contactExists = false;

        // 检查联系人是否在列表中
        for (String contactPerson : contact) {
            if (contactPerson != null && contactPerson.equals(recipient)) {
                contactExists = true;
                break;
            }
        }

        if (contactExists) {
            System.out.println("给" + recipient + "发送信息，内容为: " + message);
        } else {
            System.out.println("给匿名用户发送信息，内容为：" + message);
        }
    }
}
